﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 纺织贸易管理系统;

namespace BLL
{
    public  class 原料销售单BLL
    {
        public static void 保存单据(DanjuTable danju, List<ImportAndExportOfRawMaterials> raws)
        {
            try
            {
                Connect.dbcontext.Insertable(danju).ExecuteCommand();
                Connect.dbcontext.Insertable<ImportAndExportOfRawMaterials>(raws).ExecuteCommand();
                库存BLL.原料出库(raws);
                财务BLL.增加应收款(danju);
                来往明细BLL.增加来往记录(danju);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void 删除单据(string danhao)
        {
            var danju = Connect.dbcontext.Queryable<DanjuTable>().First(x => x.dh == danhao);
            var raws = Connect.dbcontext.Queryable<ImportAndExportOfRawMaterials>().Where(x => x.DocNum == danhao).ToList();
            try
            {
                Connect.dbcontext.Deleteable(danju).ExecuteCommand();
                Connect.dbcontext.Deleteable(raws).ExecuteCommand();
                库存BLL.原料入库(raws);
                财务BLL.减少应收款(danju);
                来往明细BLL.删除来往记录(danju);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static void 修改单据(DanjuTable danju, List<ImportAndExportOfRawMaterials> raws)
        {
            删除单据(danju.dh);
            保存单据(danju, raws);
        }
    }
}
